package com.endoc.base.utils;

import android.content.Context;



import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;



public class Utils {


    public static Calendar getBengCalendar(byte[] receiveData){
        //当前设备时间
        Calendar deviceTime = Calendar.getInstance();
        deviceTime.set(2000+receiveData[0],receiveData[1]-1,receiveData[2],receiveData[3],receiveData[4],receiveData[5]);
        LogUtils.LogD("getBengCalendar","current time:"+new SimpleDateFormat("yyyy-MM-dd HH:mm").format(deviceTime.getTime()));
        return deviceTime;
    }

    public static String getFormatCalendar(long timer){
       return new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date(timer));
    }

    /**
     * @param value byte数组
     * @return 长整型
     */
    public static long getNumber(byte []value){
        return ((value[0]&0xff)|((value[1]<<8)&0xff00)|((value[2]<<16)&0xff0000)|((value[3]<<24)&0xff000000));
    }

    /**
     * @param value 要转换的类型
     * @return byte数组
     */
    public static byte[] getNumberBytes(long value){
        return new byte[]{ (byte) value, (byte) (value>>8), (byte) (value>>16),(byte) (value>>24)};
    }

    public static byte[] getCalendarBytes(long value){
        Calendar instance = Calendar.getInstance();
        instance.setTimeInMillis(value);
        int year = instance.get(Calendar.YEAR);
        int month =instance.get(Calendar.MONTH);
        int day =instance.get(Calendar.DAY_OF_MONTH);
        int hour = instance.get(Calendar.HOUR_OF_DAY);
        int minute = instance.get(Calendar.MINUTE);
        int second = instance.get(Calendar.SECOND);
        return new byte[]{(byte) (year-2000), (byte) (month+1), (byte) day, (byte) hour, (byte) minute, (byte) second};
    }

}
